package com.jza04.flightbooking.mapper;

import com.jza04.flightbooking.entity.Discount;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

/**
 * 折扣Mapper接口
 */
@Mapper
public interface DiscountMapper {
    
    /**
     * 查询所有折扣
     */
    @Select("SELECT * FROM discount_JZA04")
    List<Discount> findAll();
    
    /**
     * 根据ID查询折扣
     */
    @Select("SELECT * FROM discount_JZA04 WHERE discount_id = #{discountId}")
    Discount findById(Integer discountId);
    
    /**
     * 查询当前有效的折扣
     */
    @Select("SELECT * FROM discount_JZA04 WHERE start_date <= #{currentDate} AND end_date >= #{currentDate}")
    List<Discount> findValidDiscounts(Date currentDate);
    
    /**
     * 添加折扣
     */
    @Insert("INSERT INTO discount_JZA04(discount_name, discount_rate, start_date, end_date, description) " +
            "VALUES(#{discountName}, #{discountRate}, #{startDate}, #{endDate}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "discountId")
    int insert(Discount discount);
    
    /**
     * 更新折扣
     */
    @Update("UPDATE discount_JZA04 SET discount_name = #{discountName}, discount_rate = #{discountRate}, " +
            "start_date = #{startDate}, end_date = #{endDate}, description = #{description} " +
            "WHERE discount_id = #{discountId}")
    int update(Discount discount);
    
    /**
     * 删除折扣
     */
    @Delete("DELETE FROM discount_JZA04 WHERE discount_id = #{discountId}")
    int delete(Integer discountId);
} 